package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant;
import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.Setmeal;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.mapper.*;
import com.sky.result.PageResult;
import com.sky.service.DishService;
import com.sky.service.DishService1;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
@Slf4j
public class DishServiceImpl1 implements DishService1 {

    @Autowired
    private DishMapper1 dishMapper1;
    @Autowired
    private DishFlavorMapper1 dishFlavorMapper1;

    @Override
    public List<DishVO> listWithFlavor(Dish dish) {

        List<DishVO> dishVOList = new ArrayList<>();

        List<Dish> list = dishMapper1.list(dish);
        for (Dish dish0 : list) {
            DishVO dishVO = new DishVO();
            BeanUtils.copyProperties(dish0, dishVO);
            Long dishId = dish0.getId();
            List<DishFlavor> dishFlavors = dishFlavorMapper1.getByDishId(dishId);
            dishVO.setFlavors(dishFlavors);
            dishVOList.add(dishVO);
        }
        return dishVOList;
    }
}
